package community.hospital.controller;

import community.hospital.annotation.Log;
import community.hospital.annotation.Module;
import community.hospital.annotation.NeedLogin;
import community.hospital.annotation.NeedPermission;
import community.hospital.common.Add;
import community.hospital.common.BaseRemove;
import community.hospital.common.R;
import community.hospital.common.Update;
import community.hospital.entity.request.MenuRequest;
import community.hospital.service.application.MenuApplicationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static community.hospital.common.Constant.*;
import static community.hospital.common.PermissionConstant.*;

/**
 * @Author：ydj
 * @Date：2023/1/26 20:59
 */
@RestController
@RequestMapping("/menu")
@Module("菜单")
public class MenuController {
    @Resource
    private MenuApplicationService menuApplicationService;

    @PostMapping("/addMenu")
    @NeedLogin
    @NeedPermission(role = SUPER_ADMIN, permission = ADD_MENU)
    @Log(methodName = LOG_QUERY,desc = "查询菜单")
    public R<Boolean> addMenu(@Validated(Add.class) @RequestBody MenuRequest request) {
        Boolean isOk = menuApplicationService.addMenu(request);
        return R.ok(isOk);
    }
    @Log(methodName = LOG_UPDATE,desc = "更新菜单")
    @PostMapping("/updateMenu")
    @NeedLogin
    @NeedPermission(role = SUPER_ADMIN, permission = UPDATE_MENU)
    public R<Boolean> updateMenu(@Validated(Update.class) @RequestBody MenuRequest request) {
        Boolean isOk = menuApplicationService.updateMenu(request);
        return R.ok(isOk);
    }
    @Log(methodName = LOG_REMOVE,desc = "删除菜单")
    @PostMapping("/removeMenu")
    @NeedLogin
    @NeedPermission(role = SUPER_ADMIN, permission = REMOVE_MENU)
    public R<Boolean> updateMenu(@Validated @RequestBody BaseRemove baseRemove) {
        Boolean isOk = menuApplicationService.removeMenus(baseRemove.getIds());
        return R.ok(isOk);
    }


}
